<template>
 <div>

    <div class="header">
      <span>说明：目前支持学科和关键字条件筛选</span>
     <addbuttonVue @click.native="$router.push('/questions/new')"  />
    </div>

  <el-form ref="form" :model="form">
  <el-row>
  <el-col :span="6"><el-form-item label="学科"  >
    <el-select v-model="form.subjectID"  placeholder="请选择"   @change="getDirectory">
          <el-option v-for="item in subjectList" :key="item.value" :value="item.value" :label="item.label">
      </el-option>
    </el-select></el-form-item></el-col>
  <el-col :span="6"><el-form-item label="二级目录"><el-select  placeholder="请选择" v-model="form.catalogID"  >
          <el-option v-for="item in directoryList" :key="item.value" :value="item.value" :label="item.label">
      </el-option>
    </el-select></el-form-item></el-col>
  <el-col :span="6"><el-form-item label="标签"><el-select  placeholder="请选择" v-model="form.tags"  >
           <el-option v-for="item in tagsList" :key="item.value" :value="item.label" :label="item.label">
      </el-option>
    </el-select></el-form-item></el-col>
<el-col :span="6"><el-form-item label="关键字">
<el-input  placeholder="请输入" v-model="form.keywords" ></el-input>
</el-form-item></el-col>
</el-row>
  <el-row>
  <el-col :span="6"><el-form-item label="试题类型"  ><el-select  placeholder="请选择" v-model="form.questionType" >
          <el-option v-for="item in questionType" :key="item.value" :value="item.value" :label="item.label">
      </el-option>
    </el-select></el-form-item></el-col>
  <el-col :span="6"><el-form-item label="难度"  ><el-select  placeholder="请选择" v-model="form.difficulty" >
              <el-option v-for="item in difficulty" :key="item.value" :value="item.value" :label="item.label">
      </el-option>
    </el-select></el-form-item></el-col>
  <el-col :span="6"><el-form-item label="方向"  ><el-select  placeholder="请选择" v-model="form.direction" >
                 <el-option
      v-for="(item,index) in direction"
      :key="index"
      :label="item"
      :value="item">
    </el-option>
    </el-select></el-form-item></el-col>
      <el-col :span="6"><el-form-item label="录入人"  ><el-select  placeholder="请选择" v-model="form.username" >
       <el-option
      v-for="(item,index) in userlist"
      :key="index"
      :label="item.username"
      :value="item.id">
    </el-option>
    </el-select></el-form-item></el-col>
</el-row>
  <el-row>
  <el-col :span="6"><el-form-item label="题目备注"  ><el-input  placeholder="请输入" v-model="form.remarks"  ></el-input>
    </el-form-item></el-col>
  <el-col :span="6"><el-form-item label="企业简称" ><el-input  placeholder="请输入" v-model="form.enterpriseID" ></el-input>
    </el-form-item></el-col>
  <el-col :span="6"><el-form-item label="城市" class="el_form_item" ><el-select  placeholder="请选择" size="mini" @visible-change="getProvince" @change="getCity" v-model="form.province" >
           <el-option
      v-for="(item,index) in provincesOptions"
      :key="index"
      :label="item"
      :value="item">
    </el-option>
    </el-select>
    <el-select  placeholder="请选择" size="mini" v-model="form.city" >
            <el-option
      v-for="(item,index) in cityOptions"
      :key="index"
      :label="item"
      :value="item">
    </el-option>
    </el-select>
    </el-form-item></el-col>
      <el-col :span="6" class="el_col" ><searchbtnVue @searchForm="searchForm" @removeForm="removeForm" /></el-col>
</el-row>
</el-form>
 </div>
</template>

<script>
import addbuttonVue from '../components/addbutton.vue'
import searchbtnVue from './searchbtn.vue'
import { simple } from '@/api/hmmm/subjects.js'
import { list } from '@/api/hmmm/companys.js'
import { simpleDirectory } from '@/api/hmmm/directorys.js'
import { provinces, citys } from '@/api/hmmm/citys.js'
import { direction, questionType, difficulty } from '@/api/hmmm/constants.js'
import { simpleTag } from '@/api/hmmm/tags.js'
import { simple as usersimple } from '@/api/base/users.js'

export default {
  name: 'commonHeader',
  props: {
    type: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      subjectList: [],
      directoryList: [],
      provincesOptions: [],
      cityOptions: [],
      direction: direction,
      questionType: questionType,
      difficulty: difficulty,
      tagsList: [],
      userlist: [],
      form: {
        subjectID: '',
        catalogID: '',
        enterpriseID: '',
        direction: '',
        questionType: '',
        difficulty: '',
        question: '',
        remarks: '',
        tags: '',
        province: '',
        city: '',
        keywords: '',
        username: ''
      }

    }
  },
  components: {
    addbuttonVue, searchbtnVue
  },
  async created () {
    const { data } = await simple()
    this.subjectList = data
    const res = await list({ pagesize: 10000 })
    const dat = await usersimple()
    this.userlist = dat.data
    res.data.items.forEach(item => {
      if (item.company) {
        this.companyList.push({ label: item.company, value: item.id })
      }
    })
  },
  methods: {
    async getDirectory (e) {
      const { data } = await simpleDirectory({ subjectID: e })
      const res = await simpleTag({ subjectID: e })
      this.tagsList = res.data
      this.directoryList = data
    },
    getProvince (value) {
      if (value) {
        this.provincesOptions = provinces()
      }
    },
    getCity (e) {
      if (e) {
        this.cityOptions = citys(e)
      }
    },
    searchForm () {
      this.$emit('getNewList', this.form)
    },
    removeForm () {
      this.form = {
        subjectID: '',
        catalogID: '',
        enterpriseID: '',
        direction: '',
        questionType: '',
        difficulty: '',
        question: '',
        remarks: '',
        tags: '',
        province: '',
        city: '',
        keywords: '',
        username: ''
      }
      this.$emit('removeForm')
    }
  }
}
</script>

<style scoped lang='less'>
.header{
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  span{
    font-size: 12px;
    color: pink;
  }
}
  .el-row {
    margin-bottom: 20px;
  /deep/ .el-form-item{
    width: 400px;
    display: flex;
    height: 32px;
    line-height: 32px;
    font-size: 12px;
  }
      /deep/.el-input__inner{
      height: 32px;
      width: 298px;
    }
    .el-col-6{
      display: flex;
      height: 32px;
      /deep/.el-input__suffix{
        width: 25px;
      }
/deep/.el-form-item__label{
  width: 68px;
  height: 32px;
}
/deep/.minbox{
  padding-left: 14px;
}
    }
   /deep/ .el-select{
      margin-right: 15px;
      padding: 0;
    }
    &:last-child {
      margin-bottom: 0;
    }
  }
  /deep/.el-form{
    margin-bottom: 15px;
  }
  // .el-col-3{
  //   display: flex;

  // }
  .el_form_item{
    display: flex;

    /deep/.el-input__inner{
      width: 130px;
      padding-right: 0;
    }
  }
  .el_col{
    display: flex;
    justify-content: end;
  }
</style>
